import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class DataTableDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('DataTable'),
        centerTitle: true,
      ),
      body: DataTable(
        //索引
        sortColumnIndex: 1,
        //索引-升序或者降序
        sortAscending: true,
        //表头  numeric:某一列右对齐  tooltip:长按表头提示
        columns: [
          DataColumn(label: Text('姓名'),tooltip: '长按提示'),
          DataColumn(label: Text('年纪'),numeric: true),
        ],
        //内容  selected:设置某一行被选中
        rows: [
          DataRow(cells: [
            DataCell(Text('张三')),
            DataCell(Text('18')),
          ],selected: true),
          DataRow(cells: [
            DataCell(Text('李四')),
            DataCell(Text('18')),
          ]),
          DataRow(cells: [
            DataCell(Text('王五')),
            DataCell(Text('18')),
          ]),
        ],
      ),
    );
  }
}
